package com.feiyu.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;


//@WebFilter(urlPatterns = "/depts")          //需要加上注解
public class FilterDemo  implements Filter {
    /**
     *  初始化   默认实现 只调用一次
     * @param filterConfig
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init初始化操作");

    }

    /**
     *
     * @param request
     * @param response
     * @param chain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("demo拦截到请求");

        chain.doFilter(request,response);
        System.out.println("放行后");
    }

    /**
     * 销毁   默认实现   只调用一次
     */
    @Override
    public void destroy() {
        System.out.println("destroy+销毁");

    }
}
